package com.example.questionnaire.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.example.common.utils.Constant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.example.questionnaire.entity.TeamEntity;
import com.example.questionnaire.service.TeamService;
import com.example.common.utils.PageUtils;
import com.example.common.utils.R;



/**
 * 
 *
 * @author hsz
 * @email 1416446590@qq.com
 * @date 2022-10-29 09:51:04
 */
@Api("群组管理")
@CrossOrigin
@RestController
@RequestMapping("questionnaire/group")
public class TeamController {
    @Autowired
    private TeamService teamService;

    /**
     * 列表
     */
    @ApiOperation("查询(分页、模糊、id查询)(根据sign标识符查询，能够通过sign查询出不同类型的群组)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params",  paramType = "Map<String, Object>")
    })
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = teamService.queryPage(params);
        return R.ok().put("data", page);
    }


    /**
     * id查询信息
     */
    @ApiOperation("(错误返回值已添加)(已通过)查询群组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "群组id", paramType = "int", required = true, dataType = "int"),

    })
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		TeamEntity team = teamService.getById(id);
        if(team == null){
            return R.error().put("team",null);
        }
        return R.ok().put("data", team);
    }



    /**
     * 保存
     */
    @ApiOperation("(错误返回值已添加)(已通过)添加群组")
    @PostMapping("/save")
    public R save(@RequestBody TeamEntity team){
        int result = teamService.addTeam(team);
        if(result != 0){
            return R.error().put("team",null);
        }
        return R.ok().put("data",team);
    }

    /**
     * 修改
     */
    @ApiOperation("(错误返回值已添加)(已通过)(更新群组信息,1个参数GroupEntity")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="TeamEntity" , value = "TeamEntity", paramType = "save", required = true,dataType = "TeamEntity")
    })
    @PostMapping("/update")
    public R update(@RequestBody TeamEntity team){
        if(team == null){
            return R.error().put("team",null);
        }
        teamService.updateById(team);

        return R.ok().put("data",team);
    }

    /**
     * 删除
     */
    @ApiOperation("(错误返回值已添加)删除群组信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name ="GroupEntity" , value = "GroupEntity")
    })
    @PostMapping("/delete")
    public R delete(@RequestBody TeamEntity team){
        int result = teamService.removeTeam(team);
        if(result != 0){
            return R.error().put("user/answerer exist!!!",null);
        }
        return R.ok().put("data",team);
    }



}
